import {
  LockOutlined,
  UserOutlined,
} from '@ant-design/icons';
import {
  LoginForm,
  ProFormText,
} from '@ant-design/pro-components';
import {message, Tabs} from 'antd';
import {create} from "@/services/ant-design-pro/api";


export default () => {
  const handleCreate = async (values: API.CreateParams) => {
    try {
      // 创建用户
      const suc = await create(values);
      if (suc) {
        const defaultLoginSuccessMessage = '创建成功！';
        message.success(defaultLoginSuccessMessage);
        location.reload();
        return;
      }
    } catch (error: any) {
      const defaultLoginFailureMessage = '注册失败，请重试！';
      message.error(defaultLoginFailureMessage);
    }
  };
  return (
      <div style={{ backgroundColor: 'white' }}>
        <LoginForm
          submitter={{
            searchConfig: {
              submitText: '创建用户'
            }
          }}
          logo="https://github.githubassets.com/images/modules/logos_page/Octocat.png"
          title="用户中心"
          subTitle="全球最大的用户管理平台"
          onFinish={async (values) => {
            await handleCreate(values as API.CreateParams);
          }}
        >
          <Tabs
            centered
            activeKey={'account'}
          >
            <Tabs.TabPane key={'account'} tab={'用户信息创建'} />
          </Tabs>
          {(
            <>
              <ProFormText
                name="username"
                fieldProps={{
                  size: 'large',
                  prefix: <UserOutlined className={'prefixIcon'} />,
                }}
                placeholder={'用户名'}
                rules={[
                ]}
              />
              <ProFormText
                name="userAccount"
                fieldProps={{
                  size: 'large',
                  prefix: <UserOutlined className={'prefixIcon'} />,
                }}
                placeholder={'用户账户 '}
                rules={[
                  {
                    required: true,
                    message: '请输入用户账户!',
                  },
                  {
                    min:4,
                    message: '用户账户长度不得小于4',
                  },
                ]}
              />
              <ProFormText.Password
                name="userPassword"
                fieldProps={{
                  size: 'large',
                  prefix: <LockOutlined className={'prefixIcon'} />,
                }}
                placeholder={'密码'}
                rules={[
                  {
                    required: true,
                    message: '请输入密码！',
                  },
                  {
                    min:8,
                    message:'密码长度不得小于8',
                  },
                ]}
              />
              <ProFormText
                name="planetCode"
                fieldProps={{
                  size: 'large',
                  prefix: <UserOutlined className={'prefixIcon'} />,
                }}
                placeholder={'星球编号 '}
                rules={[
                  {
                    max:5,
                    message:'星球编号不得大于5位',
                  },
                  {
                    required:true,
                    message:'星球编号必填',
                  }
                ]}
              />
              <ProFormText
                name="avatarUrl"
                fieldProps={{
                  size: 'large',
                  prefix: <UserOutlined className={'prefixIcon'} />,
                }}
                placeholder={'用户头像地址URL '}
                rules={[

                ]}
              />
              <ProFormText
                name="gender"
                fieldProps={{
                  size: 'large',
                  prefix: <UserOutlined className={'prefixIcon'} />,
                }}
                placeholder={'用户性别 '}
                rules={[
                  {
                    max:1,
                    message:'只能是1-男  0-女',
                  }
                ]}
              />
              <ProFormText
                name="phone"
                fieldProps={{
                  size: 'large',
                  prefix: <UserOutlined className={'prefixIcon'} />,
                }}
                placeholder={'用户手机号 '}
                rules={[

                ]}
              />
              <ProFormText
                name="email"
                fieldProps={{
                  size: 'large',
                  prefix: <UserOutlined className={'prefixIcon'} />,
                }}
                placeholder={'用户邮箱 '}
                rules={[
                ]}
              />
              <ProFormText
                name="userStatus"
                fieldProps={{
                  size: 'large',
                  prefix: <UserOutlined className={'prefixIcon'} />,
                }}
                placeholder={'用户状态 0-正常 '}
                rules={[
                  {
                    max:1,
                    message:'只能有一位表示状态',
                  }
                ]}
              />
              <ProFormText
                name="userRole"
                fieldProps={{
                  size: 'large',
                  prefix: <UserOutlined className={'prefixIcon'} />,
                }}
                placeholder={'用户角色 0-普通用户 1-管理员 '}
                rules={[
                  {
                    max:1,
                    message:'只能有一位表示角色',
                  }
                ]}
              />
            </>
          )}
          <div
            style={{
              marginBlockEnd: 24,
            }}
          >
          </div>
        </LoginForm>
      </div>
  );
};
